import Vue from 'vue'
import Vuex from 'vuex'
import axios from "axios"
import {createLogger} from "vuex"
Vue.use(Vuex)

export default new Vuex.Store({
  plugins:[createLogger()],
  state: {
    arr:[],
    filterarr:[  // 原始得数据
       "张三","李四","王五"
    ],
    filterend:[] // 过滤之后的结果
  },
  getters: {
  },
  mutations: {
    setArr (state,payload) {
        state.arr = payload
    },
    filterdata(state,payload) {
        console.log(payload)
       state.filterend =  state.filterarr.filter((item,index)=>{
           if (payload) {
            return item.includes(payload)
           } else {
              return null
           }
         
         })
        
    }
  },
  actions: {
    getList({commit},payload){
        console.log(payload);
        axios.get("/list",{params:{title:payload}}).then(res=>{
            console.log(res.data.children);
            commit("setArr",res.data.children)
        })
    }
  },
  modules: {
  }
})
